function mySetInterval(fn, time) {
  let timer = null
  function interval() {
    fn()
    timer = setTimeout(interval, time)
  }
  interval()
  return {
    cancel: () => {
      clearTimeout(timer)
    },
  }
}

let timer = mySetInterval(() => {
  console.log('mySetInterval')
}, 1000)
setTimeout(() => {
  timer.cancel()
}, 3500)

function mySetTimeout(fn, time) {
  let timer = setInterval(() => {
    fn()
    clearInterval(timer)
  }, time)
}
